#!/bin/bash

set -e

pushd rust
git checkout master
#a#git checkout .gitmodules
git clean -dfx
#git checkout configure #to undo patch, or git reset --hard
git reset --hard
git pull #|| git update-server-info && git pull
#make clean #won't work if git clean is before this
# yes they say I should do a make clean after a git pull, so... there:)

#here for good measure, I do this:
#a#patch -Np1 -i ../62ad301_and_patch_for_rust_issue_28947.patch
#a#currentremote="`cd .git/modules/src/llvm && git remote -v show | head -1 |cut -f2 -d$'\x9'|cut -f1 -d' '`"
#a##yields: https://github.com/zazdxscf/llvm.git
#a#newremote="`cat .gitmodules |grep llvm\.git|cut -f3 -d' '`"
#a##yields: https://github.com/zazdxscf/llvm.git
#a#if test -z "$currentremote" -o -z "$newremote"; then
#a#  echo "something went wrong: old:'$currentremote' new:'$newremote'"
#a#  exit 1
#a#fi
#a#if test -n "$currentremote" -a -n "$newremote" -a "$currentremote" != "$newremote"; then
#a#  echo "!! Removing old llvm .git due to remote change; old: $currentremote new: $newremote"
#a#  rm -rf .git/modules/src/llvm
#a#  rm -rf src/llvm
#a#fi

patch -Np1 -i ../local_rust_libfix.patch
patch -Np1 -i ../llvm_only_x86_64_and_arm.patch
#patch -Np1 -i ../llvm_yes_debug.patch
patch -Np1 -i ../llvm_extra_debug_when_no_optimize.patch
#patch -Np1 -i ../equivalent_of_unset_RUST_BACKTRACE.patch
#patch -Np1 -i ../le.patch
#patch -Np1 -i ../le2.patch
patch -Np1 -i ../32746.patch

popd
./conf

